package com.js.fegin.fallback;


import cn.js.dto.User;
import com.js.fegin.UserFeignClientApi;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;


@Component
public class UserFeignClientApiFallback implements FallbackFactory<UserFeignClientApi> {

    @Override
    public UserFeignClientApi create(Throwable throwable) {
        return new UserFeignClientApi(){
            @Override
            public User getByApiId(Long userId) {
                //打印异常信息，方便从控制台查看触发兜底的原因
                throwable.printStackTrace();
                return new User(userId, "null", "User服务不可用，返回兜底数据",null);
            }
        };
    }
}
